﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataAccess.DataObject;

namespace DataAccess.BusinessObject
{
    public class BCategory_Product : Common.CDBase
    {
        /// <summary>
        /// Thêm chuyên mục cho sản phẩm
        /// </summary>
        /// <param name="IDCat"></param>
        /// <param name="IDProduct"></param>
        /// <returns></returns>
        public bool Add(int IDCat, int IDProduct)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDCat",SqlDbType.Int),
                                        new SqlParameter("@IDProduct",SqlDbType.Int)};
            sqlParam[0].Value = IDCat;
            sqlParam[1].Value = IDProduct;
            return RunProcedure("sp_tblCategory_Product_add", sqlParam);
        }
        public bool Delete(int IDProduct)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDProduct", SqlDbType.Int) };
            sqlParam[0].Value = IDProduct;
            return RunProcedure("sp_tblCategory_Product_delete", sqlParam);
        }
        /// <summary>
        /// Đếm số sản phẩm trong category
        /// </summary>
        /// <param name="CatID"></param>
        /// <returns></returns>
        public int CountProduct(int CatID)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@CatID", SqlDbType.Int) };
            sqlParam[0].Value = CatID;
            DataTable dtb = RunProcedureGet("sp_tblCategory_Product_countproduct", sqlParam);
            return int.Parse(dtb.Rows[0]["Count"].ToString());
        }
        public IList<OCategory_Product> Get(int IDProduct)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDProduct", SqlDbType.Int) };
            sqlParam[0].Value = IDProduct;
            return Common.Common.ConvertTo<OCategory_Product>(RunProcedureGet("sp_tblCategory_Product_get", sqlParam));
        }
    }
}
